//
//  XNApproveTableViewCell.m
//  XINNingOA
//
//  Created by samuel on 2021/7/12.
//

#import "XNApproveTableViewCell.h"

@interface XNApproveTableViewCell()

@property (nonatomic, weak) UILabel *dateLab;

@property (nonatomic, weak) UILabel *dotLab;

@property (nonatomic, weak) UILabel *topLab;

@property (nonatomic, weak) UILabel *bottomLab;

@property (nonatomic, weak) UILabel *nameLab;

@property (nonatomic, weak) UILabel *remarkLab;

@property (nonatomic, weak) UILabel *stateLab;

@end

@implementation XNApproveTableViewCell

+ (instancetype)tabelViewCellWithTableView:(UITableView *)tableView
                                  ForIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"XNApproveTableViewCellID";
    XNApproveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[XNApproveTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSubView];
    }
    return self;
}

- (void)setSubView
{
    UILabel *dateLab = [[UILabel alloc] init];
    dateLab.font = [UIFont systemFontOfSize:10];
    dateLab.numberOfLines = 0;
    [self.contentView addSubview:dateLab];
    self.dateLab = dateLab;
    [dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(60);
    }];
    
    UILabel *dotLab = [[UILabel alloc] init];
    dotLab.backgroundColor = [UIColor grayColor];
    dotLab.layer.cornerRadius = 5;
    dotLab.clipsToBounds = YES;
    [self.contentView addSubview:dotLab];
    self.dotLab = dotLab;
    [dotLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(10, 10));
        make.left.equalTo(dateLab.mas_right).offset(10);
    }];

    UILabel *topLab = [[UILabel alloc] init];
    topLab.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:topLab];
    self.topLab = topLab;
    [topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.centerX.equalTo(dotLab);
        make.width.mas_equalTo(1);
        make.bottom.equalTo(dotLab.mas_top).offset(-5);
    }];

    UILabel *bottomLab = [[UILabel alloc] init];
    bottomLab.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:bottomLab];
    self.bottomLab = bottomLab;
    [bottomLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView);
        make.centerX.equalTo(dotLab);
        make.width.mas_equalTo(1);
        make.top.equalTo(dotLab.mas_bottom).offset(5);
    }];

    UILabel *nameLab = [[UILabel alloc] init];
    nameLab.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:nameLab];
    self.nameLab = nameLab;
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dotLab.mas_right).offset(10);
        make.height.mas_equalTo(16);
        make.top.equalTo(self.contentView).offset(10);
    }];

    UILabel *remarkLab = [[UILabel alloc] init];
    remarkLab.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:remarkLab];
    self.remarkLab = remarkLab;
    [remarkLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dotLab.mas_right).offset(10);
        make.height.mas_equalTo(12);
        make.top.equalTo(nameLab.mas_bottom).offset(10);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];

    UILabel *stateLab = [[UILabel alloc] init];
    stateLab.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:stateLab];
    self.stateLab = stateLab;
    [stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLab.mas_right).offset(10);
        make.bottom.equalTo(nameLab);
        make.height.mas_equalTo(12);
        make.right.lessThanOrEqualTo(self.contentView);
    }];
    
}

- (void)setApproveModel:(XNBillApproveModel *)approveModel
{
    _approveModel = approveModel;
    self.dateLab.text = approveModel.checkTimeStr;
    if (approveModel.seq == 1) {
        self.topLab.hidden = YES;
    }else{
        self.topLab.hidden = NO;
    }
    self.nameLab.text = [NSString stringWithFormat:@"%@(%@)",approveModel.checkAccountUserName,approveModel.processName];
    self.stateLab.text = approveModel.statusStr;
    if (approveModel.remark.length > 0) {
        self.remarkLab.text = approveModel.remark;
        [self.remarkLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(12);
        }];
    }else{
        [self.remarkLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    }
    
    if([approveModel.status isEqualToString:@"CS020"]){
        self.bottomLab.hidden = YES;
        self.dateLab.textColor = [UIColor colorWithHexString:@"#358AFF"];
        self.dotLab.backgroundColor = [UIColor colorWithHexString:@"#358AFF"];
        self.nameLab.textColor = [UIColor colorWithHexString:@"#358AFF"];
        self.stateLab.textColor = [UIColor colorWithHexString:@"#358AFF"];
        self.remarkLab.textColor = [UIColor colorWithHexString:@"#358AFF"];
    }else{
        self.bottomLab.hidden = NO;
        self.dateLab.textColor = [UIColor grayColor];
        self.dotLab.backgroundColor = [UIColor grayColor];
        self.nameLab.textColor = [UIColor grayColor];
        self.stateLab.textColor = [UIColor grayColor];
        self.remarkLab.textColor = [UIColor grayColor];
    }

}

@end
